package com.tk.component;

import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 *@Author shen chen
 *@Date 2024-04-13
 */
@Slf4j
@Component
public class InitCommand implements CommandLineRunner {
    @Override
    public void run(String... args) {
        try {
            //  win
            SerialPortManager.connectSerialPort("COM3");
            //  linux centos
            // SerialPortManager.connectSerialPort("ttyS1");
        } catch (Exception e) {
            log.error("ERROR SerialPortManager.connectSerialPort cause:", e);
        }
    }

    @PreDestroy
    public void destroy() {
        SerialPortManager.closeSerialPort();
    }
}
